package com.dongdong.controller;

import com.dongdong.model.TbItem;
import com.dongdong.result.Result;
import com.dongdong.service.ItemService;
import com.dongdong.service.TbItemCatService;
import com.dongdong.vo.TbItemCatVO;
import com.dongdong.vo.TypeTemplateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private ItemService itemService;

    @GetMapping("/selectBySkuId")
    public TbItem selectBySkuId(@RequestParam Long skuId){
        return itemService.selectBySkuId(skuId);

    }


    //扣减库存
    @PostMapping("/stockCount")
    public void stockCount(@RequestBody List<TbItem> items){
        for (TbItem item : items) {
            //itemId num   56213    2
            TbItem tbItem = itemService.selectBySkuId(item.getId());
            tbItem.setStockCount(tbItem.getStockCount() - item.getStockCount());
            // 更新
            itemService.updateStockCount(tbItem);

        }

    }













}